package com.sugar.subscribe.course.module.business.controller.app.coachcertificate;

import com.sugar.subscribe.course.framework.apilog.core.annotation.ApiAccessLog;
import com.sugar.subscribe.course.framework.common.pojo.CommonResult;
import com.sugar.subscribe.course.framework.common.pojo.PageParam;
import com.sugar.subscribe.course.framework.common.pojo.PageResult;
import com.sugar.subscribe.course.framework.common.util.object.BeanUtils;
import com.sugar.subscribe.course.framework.excel.core.util.ExcelUtils;
import com.sugar.subscribe.course.framework.security.core.util.SecurityFrameworkUtils;
import com.sugar.subscribe.course.module.business.controller.admin.coachcertificate.vo.CoachCertificatePageReqVO;
import com.sugar.subscribe.course.module.business.controller.admin.coachcertificate.vo.CoachCertificateRespVO;
import com.sugar.subscribe.course.module.business.controller.admin.coachcertificate.vo.CoachCertificateSaveReqVO;
import com.sugar.subscribe.course.module.business.controller.app.coachcertificate.vo.AppCoachCertificateRespVO;
import com.sugar.subscribe.course.module.business.controller.app.coachcertificate.vo.AppCoachCertificateSaveReqVO;
import com.sugar.subscribe.course.module.business.dal.dataobject.coachcertificate.CoachCertificateDO;
import com.sugar.subscribe.course.module.business.service.coachcertificate.CoachCertificateService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

import static com.sugar.subscribe.course.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static com.sugar.subscribe.course.framework.common.pojo.CommonResult.success;

@Tag(name = "APP - 教练证书")
@RestController
@RequestMapping("/biz/coach-certificate")
@Validated
public class AppCoachCertificateController {

    @Resource
    private CoachCertificateService coachCertificateService;

    @PostMapping("/create")
    @Operation(summary = "创建教练证书")
    public CommonResult<Long> createCoachCertificate(@Valid @RequestBody AppCoachCertificateSaveReqVO createReqVO) {
        return success(coachCertificateService.appCreateCoachCertificate(createReqVO, SecurityFrameworkUtils.getLoginUserId(true)));
    }

    @GetMapping("/delete")
    @Operation(summary = "删除教练证书")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteCoachCertificate(@RequestParam("id") Long id) {
        coachCertificateService.deleteCoachCertificate(id);
        return success(true);
    }

    @GetMapping("/page")
    @Operation(summary = "获得教练证书分页")
    public CommonResult<PageResult<AppCoachCertificateRespVO>> getCoachCertificatePage(@Valid PageParam pageParam) {
        return success(coachCertificateService.appGetCoachCertificatePage(pageParam, SecurityFrameworkUtils.getLoginUserId(true)));
    }
}